package com.xc.stock.constant;

import com.ag.exception.SysTipsException;

/**
 * @author xlfd
 * @email xlfd@gmail.com
 * @version 1.0
 * @created Jan 13, 2021 11:53:31 AM
 */
public enum StockSource {
	A("A", "A股"), HK("HK", "港股"), US("US", "美股"),;

	String code;
	String remark;

	StockSource(String code, String remark) {
		this.code = code;
		this.remark = remark;
	}

	public String code() {
		return code;
	}

	public String remark() {
		return remark;
	}

	public static String remark(String code) {
		StockSource of = of(code);
		return of == null ? "" : of.remark;
	}

	public static StockSource of(String code) {
		StockSource[] values = StockSource.values();
		for (StockSource e : values) {
			if (e.code.equals(code)) {
				return e;
			}
		}

		return null;
	}

	public Currency currency() {
		if (this == A) {
			return Currency.CNY;
		} else if (this == HK) {
			return Currency.HKD;
		} else if (this == US) {
			return Currency.USD;
		}
		
		throw new SysTipsException("无法转换到对应币种.");
	}
}
